/*************************************************************************  
 *   This file is part of UBBMPSREADER.
 *
 *   UBBMPSREADER is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   UBBMPSREADER is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with UBBMPSREADER.  If not, see <http://www.gnu.org/licenses/>. 
 *************************************************************************/

package cs.ubbcluj.ro.mps.data;

import java.util.LinkedHashMap;
import java.util.Map;

import cs.ubbcluj.ro.mps.data.interfaces.Constrain;

/**
 * A constrain from the MPS file (an equation)
 * 
 * @author avadas
 * @version 1.0
 */
public strictfp class ConstrainImpl implements Constrain {

    /** The name of the constrain */
    private final String name;

    /** The type of the constrain */
    private final ConstrainType type;

    /** The variables of the constrain */
    private final Map<String, Double> variables;

    /**
     * Constructor
     * 
     * @param type
     *            the type of the constrain
     */
    public ConstrainImpl(final String name, final ConstrainType type) {
	this.name = name;
	this.type = type;
	this.variables = new LinkedHashMap<String, Double>();
    }

    /**
     * Returns the name of the constrain (equation)
     * 
     * @return the name of the constrain
     */
    public String getName() {
	return this.name;
    }

    /**
     * Adds a variable to the constrain
     * 
     * @param variableName
     *            the name of the variable
     * @param coeficient
     *            the coefficient
     */
    public void addVariable(final String variableName, final double coeficient) {
	this.variables.put(variableName, coeficient);
    }

    /**
     * 
     * @param variableName
     *            the variableName
     * @return true if the variable has different value from zero (is present)
     */
    public boolean containsVariable(final String variableName) {

	return this.variables.containsKey(variableName);
    }

    /**
     * 
     * @return all variables with coefficient different from zero
     */
    public Map<String, Double> getVariables() {
	return this.variables;
    }

    /**
     * 
     * @param variableName
     *            the name of the variable
     * @return
     */
    public double getCoefficient(final String variableName) {
	return this.variables.get(variableName);
    }

    /**
     * 
     * @return the type of the constrain (L, G, E, N)
     */
    public ConstrainType getType() {
	return this.type;
    }
}
